"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function responseSISFormat() {
    return async (ctx, next) => {
        const startDate = new Date();
        await next();
        const passTime = new Date().getTime() - startDate.getTime();
        const isResponseJson = ctx.response?.header?.['content-type'] === 'application/json;charset=utf-8';
        const SISFormat = ctx.response?.header?.['sis-format'] === 'on';
        if (isResponseJson && SISFormat) {
            const responseJson = ctx.body === 'string' ? JSON.parse(ctx.body) : ctx.body;
            const message = responseJson?.message || '操作成功';
            const data = responseJson?.data || null;
            ctx.body = JSON.stringify({
                code: ctx.response?.status || 500,
                apiCost: `耗时：${passTime} ms`,
                timestamp: new Date().toLocaleString(),
                message: message,
                data: data
            }, null, 4);
        }
    };
}
exports.default = responseSISFormat;
